#include "board.h"
#include "stm32f0xx_it.h"
#include "uart.h"
/******************************************************************************/
/*           Cortex-M0 Processor Interruption and Exception Handlers          */ 
/******************************************************************************/
/**
  * @brief This function handles Non maskable interrupt.
  */
void NMI_Handler(void)
{
  /* USER CODE BEGIN NonMaskableInt_IRQn 0 */

  /* USER CODE END NonMaskableInt_IRQn 0 */
  /* USER CODE BEGIN NonMaskableInt_IRQn 1 */

  /* USER CODE END NonMaskableInt_IRQn 1 */
}

/**
  * @brief This function handles Hard fault interrupt.
  */
void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */

  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
    /* USER CODE BEGIN W1_HardFault_IRQn 0 */
    /* USER CODE END W1_HardFault_IRQn 0 */
  }
}

/**
  * @brief This function handles System service call via SWI instruction.
  */
void SVC_Handler(void)
{
  /* USER CODE BEGIN SVC_IRQn 0 */

  /* USER CODE END SVC_IRQn 0 */
  /* USER CODE BEGIN SVC_IRQn 1 */

  /* USER CODE END SVC_IRQn 1 */
}

/**
  * @brief This function handles Pendable request for system service.
  */
void PendSV_Handler(void)
{
  /* USER CODE BEGIN PendSV_IRQn 0 */

  /* USER CODE END PendSV_IRQn 0 */
  /* USER CODE BEGIN PendSV_IRQn 1 */

  /* USER CODE END PendSV_IRQn 1 */
}

/**
  * @brief This function handles System tick timer.
  */
void SysTick_Handler(void)
{
  /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */
  HAL_IncTick();
  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */
}

/******************************************************************************/
/* STM32F0xx Peripheral Interrupt Handlers                                    */
/* Add here the Interrupt Handlers for the used peripherals.                  */
/* For the available peripheral interrupt handler names,                      */
/* please refer to the startup file (startup_stm32f0xx.s).                    */
/******************************************************************************/

/* USER CODE BEGIN 1 */
// void USART1_IRQHandler(void)
// {
//   HAL_UART_IRQHandler(&huart1);
//   if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE) != RESET) {
//     __HAL_UART_CLEAR_IDLEFLAG(&huart1);
//     HAL_UART_RxCpltCallback(&huart1);
//   }
// }

void USART2_IRQHandler(void)
{
  HAL_UART_IRQHandler(&huart2);
  if(__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE) != RESET) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart2);
    HAL_UART_RxCpltCallback(&huart2);
  }
}

void USART3_6_IRQHandler(void)
{
  HAL_UART_IRQHandler(&huart3);
  if(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_IDLE) != RESET) {
    __HAL_UART_CLEAR_IDLEFLAG(&huart3);
    HAL_UART_RxCpltCallback(&huart3);
  }
}

void DMA1_Channel1_IRQHandler(void)
{
  HAL_DMA_IRQHandler(huart3.hdmarx);
}

void DMA1_Channel2_3_IRQHandler(void)
{
  // HAL_DMA_IRQHandler(huart1.hdmarx);
  // HAL_DMA_IRQHandler(hadc1.DMA_Handle);
}

void DMA1_Channel4_5_IRQHandler(void)
{
  HAL_DMA_IRQHandler(huart2.hdmarx);
}

/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
